<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

class CommonController extends Controller
{
    // 图片上传
    public function upload()
    {
        $file = Input::all();
        $file = $file['file'];
        if ($file -> isValid()) {
//            $clientName = $file->getClientOriginalName(); //获取文件名称
//            $realPath = $file->getRealPath(); // 临时文件的绝对路径
            $entension = $file->getClientOriginalExtension(); // 上传文件的后缀
            $newName = date('YmdHis') . mt_rand(100, 999) . '.' . $entension;
            $path = $file->move(public_path(). '/uploads', $newName);
            $filepath = 'uploads/' . $newName;
            return $filepath;
        }
    }
}
